import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split #继承划分训练集和测试机
from sklearn.neighbors import KNeighborsClassifier  #K近邻
import matplotlib.pyplot as plt
from collections import Counter     #用于统计分类正确的样本数
from sklearn.preprocessing import StandardScaler#导入用于归一化的包
from sklearn.model_selection import cross_val_score#k折
from sklearn.naive_bayes import GaussianNB
from sklearn.model_selection import cross_val_score

# 设置Matplotlib以支持中文
plt.rcParams['font.sans-serif'] = ['SimHei']  # 指定字体为SimHei，注意这里使用的是字体名称
plt.rcParams['axes.unicode_minus'] = False  # 解决保存图像时负号'-'显示为方块的问题

AF_input_frame=pd.read_excel('pre_treatment_data_feature_1.xlsx',sheet_name='AF_input')
nonAF_input_frame=pd.read_excel('pre_treatment_data_feature_1.xlsx',sheet_name='nonAF_input')
AF_label_frame=pd.read_excel('pre_treatment_data_feature_1.xlsx',sheet_name='AF_label')
nonAF_label_frame=pd.read_excel('pre_treatment_data_feature_1.xlsx',sheet_name='nonAF_label')

AF_input=AF_input_frame.to_numpy()
nonAF_input=nonAF_input_frame.to_numpy()
AF_label=AF_label_frame.to_numpy()
nonAF_label=nonAF_label_frame.to_numpy()


AF_label=AF_label.flatten()
nonAF_label=nonAF_label.flatten()


X=np.concatenate([AF_input,nonAF_input])
print(X.shape)
#raw_x=np.reshape(X[:,0],[-1,1])#均值项0.71
#raw_x=np.reshape(X[:,1],[-1,1])#中位数0.717
#raw_x=np.reshape(X[:,2],[-1,1])#0.79最小
#raw_x=np.reshape(X[:,3],[-1,1])#0.57最大
#raw_x=np.reshape(X[:,4],[-1,1])#0.731极差
#raw_x=np.reshape(X[:,5],[-1,1])#标准差0.786
#raw_x=np.reshape(X[:,6],[-1,1])#方差0.458
#raw_x=np.reshape(X[:,7],[-1,1])#熵
#raw_x=X[:,[1,2]]#01-0.721 02-0.747 03-0.734 04-0.812 05-0.819 12-0.754  13-0.733
#print(raw_x)

raw_y=np.concatenate([AF_label[0:],nonAF_label[0:]])
acc_list=[]

#k=10
example_list=['均值','中值','最大值','最小值','极差','标准差','方差','熵']
for i in range(0,8):
    raw_x=np.reshape(X[:,i],[-1,1])
    m_min=10
    m_max=10
    m_interval=1
    index=np.array(range(m_min,m_max+1,m_interval))
    for k in range(m_min,m_max+1,m_interval):
        model=GaussianNB()
        acc=cross_val_score(model,raw_x,raw_y,cv=k,scoring="accuracy")
        mean_acc=np.array(acc).mean()
        print(mean_acc)
        acc_list.append(mean_acc)
plt.plot(np.array(range(0,8)),acc_list)
plt.xticks(np.arange(8),example_list)
plt.show()